package com.cosyhut.blocks.engine;

import java.util.*;

import com.cosyhut.blocks.display.*;
import com.cosyhut.blocks.jode.*;

import com.jme.scene.*;

/**
 * 
 * @author TimWorks Jan 24, 2007
 * 
 * A Robot is compose of BlockGroups and BlockJoints. Also it has its own
 * "brain" - a piece of code that handling input signals (sent by sensor) or
 * controlling AMotors
 */
public abstract class BRobot {
	protected String            _name;
    protected Engine            _engine;
    protected GRenderer      _renderer;
    
    private ArrayList<Block>    _blocks;
    private ArrayList<ODEJoint>    _joints;

    private Node                _root;
    
    public BRobot(String name, Engine e, GRenderer r) {
    	this._name = name;
    	this._engine = e;
    	this._renderer = r;
    	
    	this._blocks = new ArrayList<Block>();
    	this._joints = new ArrayList<ODEJoint>();
    	this._root = new Node();
    	this.create();
    	this.toggleDebug();
    }
    
    public void addBlock(Block b) {
        this._blocks.add(b);
        this._root.attachChild(b.getRoot());
    }
    
    public boolean connect() {
        return true;
    }
    
    public void update() {
        // update all blocks
        Iterator i = this._blocks.iterator();
        while(i.hasNext()) {
            Block b = (Block) i.next();
            b.update();
        }
    }
    public void toggleDebug() {
        // update all blocks
        Iterator i = this._blocks.iterator();
        while(i.hasNext()) {
            Block b = (Block) i.next();
            b.toggleDebug(this._renderer);
        }
    }    
    //--------------------------------------------------------------------------
    public String getName() {
    	return this._name;
    }
    public ArrayList<Block> getBlocks() {
    	return this._blocks;
    }
    public ArrayList<ODEJoint> getJoints() {
    	return this._joints;
    }
    public Node getRoot() {
    	return this._root;
    }
    
    //--------------------------------------------------------------------------
    protected abstract void create();
}
